<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>拖车渠道银行账号信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body>
		<form id="chn_bank_acc_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
                <div class="fieldBox col_50">
                    <div class="label">开户银行</div>
                    <div class="field">
                        <select name="bkCd" id="bkCd" data-value=" " validate ="{required:true,select:true}">
                            <option value=" " selected="selected" >请选择</option>
                            <c:forEach items="${bkTypCdList}" var="kv" begin="0" step="1" varStatus="status">
                                <c:if test="${status.index == 0}">
                                    <option value="${kv.key }" checked >${kv.value }</option>
                                </c:if>
                                <c:if test="${status.index != 0}">
                                    <option value="${kv.key }">${kv.value }</option>
                                </c:if>
                            </c:forEach>
                        </select>
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">分支支行</div>
                    <div class="field">
                        <input name="accOrgNm" id="accOrgNm" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:60}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">账户名</div>
                    <div class="field">
                        <input name="accNm" id="accNm" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:30}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">开户行行号</div>
                    <div class="field">
                        <input name="bkNo" id="bkNo" type="text" class="ui-textbox" value="" validate="{ number:true, maxlength:30}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">银行账号</div>
                    <div class="field">
                        <input name="accNo" id="accNo" type="text" class="ui-textbox" value="" validate="{required:true,number:true, maxlength:30}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
			        <div class="label">账户类型</div>
			          <div class="field">
                         <select name="accTypCd" id="accTypCd" data-value=" " validate ="{required:true,select:true}">
                             <option value=" " selected="selected" >请选择</option>
			            	<c:forEach items="${accTypCdList}" var="kv" begin="0" step="1" varStatus="status">
								<c:if test="${status.index == 0}">
								     <option value="${kv.key }" checked >${kv.value }</option>
								</c:if>
							    <c:if test="${status.index != 0}">
								    <option value="${kv.key }">${kv.value }</option>
								</c:if>
							</c:forEach>
			             </select>
			             <span class="requiredSymbol">*</span>
			         </div>
			    </div>
                <!-- hide data -->
		        <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name="chnId" id="chnId" type="text" class="ui-textbox" value="${chnId}">
                      <input name="bid" id="bid" type="text" class="ui-textbox" value="${bid}">
		          </div>
		        </div>
            </div>
        </form>
	<script>
		$(function() {
            $("#chn_bank_acc_form").ligerForm({
                validate: true
            });
            initData();

        });
        //初始化表单
        function initForm(){
            $("#chn_bank_acc_form").ligerForm({
                validate: true
            });
        }
		//定义父级调用事件
        //父级窗口回调
        frameElement.dialog.onOk = function () {
            save();
        }

		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}

		//保存
		var addUrl = "<%=path%>/ass/assChnBankAcc/add.do";
		var modifyUrl = "<%=path%>/ass/assChnBankAcc/modify.do";
		function save(){
            var ligerForm = liger.get("chn_bank_acc_form");
            if (!ligerForm.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            var bid = $("#bid").val();
            var chnId = $("#chnId").val();
            var url = addUrl;
            if(bid != ""){
            	url = modifyUrl;
            }
            data["channelId"]= chnId;
            AjaxUtils.ajaxPost(url, data, addCallback);
		}


		//新增回调
		function addCallback(msg){
			var bid = $("#bid").val();
			if(msg.success == 1){
				 UIUtils.alertSuccess(msg.info);
				 parent.grid.setParm("bid",bid);
				 parent.grid.reload();
				 frameElement.dialog.close();
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}

		//修改初始化数据
		function initData(){
            var bid = $("#bid").val();
	    	if(!bid){
                return;
            } else {
                var _url = '<%=path%>/ass/assChnBankAcc/getById.do';
                AjaxUtils.ajaxGet(_url, {id:bid}, initCallback);
            }
    	}

		//初始化回调
		function initCallback(msg){
			if(msg.success == 1){
				 setData(msg.data);//设置数据
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}

		//修改时候设置页面数据
	    function setData(data){
	    	var form1 =  new liger.get("chn_bank_acc_form");
	    	form1.setData({
	    		bkCd:data.bkCd,
	    		accOrgNm:data.accOrgNm,
	    		accNm:data.accNm,
	    		accNo:data.accNo,
	    		bkNo:data.bkNo,
	    		accTypCd:data.accTypCd,
                channelId:data.channelId,
	    	});
		};

	</script>

</body>
</html>